package com.exam.web.action.privilege;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;

import com.exam.bean.privilege.SystemPrivilege;
import com.exam.service.privilege.SystemPrivilegeService;
import com.opensymphony.xwork2.ActionContext;

@Controller("systemInit")
public class SystemInit {	
	
	@Resource(name="systemPrivilegeServiceBean") 
	private SystemPrivilegeService systemPrivilegeService;

	public String execute()throws Exception {
		this.initSystemPrivilege();
		ActionContext.getContext().put("message", "初始化成功");
		return "message";
	}

	private void initSystemPrivilege() {
		if(systemPrivilegeService.getCount(SystemPrivilege.class)==0){
			List<SystemPrivilege> privileges = new ArrayList<SystemPrivilege>();
			privileges.add(new SystemPrivilege("department","view","查看组织结构","组织结构管理"));
			privileges.add(new SystemPrivilege("department","insert","添加组织结构","组织结构管理"));
			privileges.add(new SystemPrivilege("department","update","修改组织结构","组织结构管理"));
			privileges.add(new SystemPrivilege("department","delete","删除组织结构","组织结构管理"));
			privileges.add(new SystemPrivilege("department","visible","启用组织结构","组织结构管理"));
			privileges.add(new SystemPrivilege("department","disvisible","禁用组织结构","组织结构管理"));

			privileges.add(new SystemPrivilege("employee","view","查看用户资料","用户资料管理"));
			privileges.add(new SystemPrivilege("employee","insert","添加用户资料","用户资料管理"));
			privileges.add(new SystemPrivilege("employee","update","修改用户资料","用户资料管理"));
			privileges.add(new SystemPrivilege("employee","delete","删除用户资料","用户资料管理"));
			
			privileges.add(new SystemPrivilege("privilegegroup","view","查看权限组","用户权限组管理"));
			privileges.add(new SystemPrivilege("privilegegroup","insert","添加权限组","用户权限组管理"));
			privileges.add(new SystemPrivilege("privilegegroup","update","修改权限组","用户权限组管理"));
			privileges.add(new SystemPrivilege("privilegegroup","delete","删除权限组","用户权限组管理"));
			systemPrivilegeService.saves(privileges);
		}		
	}

}
